package com.jxpowernode.bitcon.btcrpccode;

import com.alibaba.fastjson.JSONObject;
import com.jxpowernode.bitcon.Constants;
import com.jxpowernode.bitcon.bean.rpcbtc.GetBlock;
import com.jxpowernode.bitcon.request.HttpUtils;
import com.jxpowernode.bitcon.service.btcservice.GetBitconService;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: Lixuewei
 * @Email:1410511702@qq.com
 * @Desc: 该类用户实现通过rpc访问调用btc的getBlockHash方法
 * @Date: 2021/12/15 19:10
 */
public class GetBlockHash {

    /**
     * 该方法通过区块高度获取区块hash值
     * @param heigt 区块的高度值
     * @return 返回区块hash值
     */
    public GetBlock getBlockHash(int[] heigt){
        GetBitconService service = new GetBitconService();
        Map<String, String> bitcon = service.getBitcon();

        Map<String,Object> boby = new HashMap<>();
        boby.put("id",1001);
        boby.put("params",heigt);
        boby.put("method","getblockhash");
        byte[] data = JSONObject.toJSONBytes(boby);
        String result = HttpUtils.post(Constants.RPC_URL, bitcon, data);;
        GetBlock getBlock = JSONObject.parseObject(result, GetBlock.class);
        return getBlock;

    }
}
